hysop.numerics.stencil.stencil module

Finite differences stencil inteface used in various numerical methods.

class hysop.numerics.stencil.stencil.CenteredStencil(coeffs, origin, order, dx=dx, factor=1, error=None, **kwds)[source]

Bases: Stencil

Centered stencil used for finite abitrary dimension differences.

Centered stencil used for finite abitrary dimension differences.

See also

CenteredStencilGenerator

Centered stencil generator.

static from_stencil(stencil)[source]
is_centered()[source]

Check if the stencil is centered (ie. stencil generate a centered finite differences scheme).

Returns:

is_centered

Return type:

bool

class hysop.numerics.stencil.stencil.Stencil(coeffs, origin, order, dx=dx, factor=1, error=None, delete_zeros=True)[source]

Bases: object

Stencil used for finite abitrary dimension differences.

Stencil used for finite differences schemes (n-dimensional).

Parameters:
  • coeffs (array_like) – Coefficients of the stencil.

  • origin (array_like) – Origin of the stencil from left-most point.

  • order (int) – Order of the stencil.

  • dx (sympy.Symbol or array_like of sympy.Symbol) – Spatial spacing symbols.

  • factor (dtype or sympy.Expr) – Common leading factors for all coefficients.

  • error (sympy.Expr) – Exact error if known.

coeffs

Coefficients of the stencil.

Type:

np.ndarray

origin

Origin of the stencil from left-most point.

Type:

np.ndarray

order

Spatial order of the stencil.

Type:

int

dim

Spatial dimension of the stencil.

Type:

int

shape

Shape of the stencil.

Type:

np.ndarray

L

Distance from origin to left-most point included in stencil support.

Type:

np.ndarray

R

Distance from origin to right-most point included in stencil support.

Type:

np.ndarray

dx

Spatial spacing symbols.

Type:

sympy.Symbol or array_like of sympy.Symbol

factor

Leading factor of all coefficients.

Type:

dtype or sympy.Expr

error

Exact error term if known or else None.

Type:

sympy.Expr

Raises:

ValueError – Raised if one component of origin is negative.

See also

CenteredStencil

Centered version of a stencil.

StencilGenerator

Generate Stencil objects.

__call__(*args, **kwds)[source]

Alias for apply.

accuracy()[source]

Accuracy of the stencil with bigO notation.

Returns:

accuracy – Accuracy in bigO notation.

Return type:

sympy.Expr

apply(a, out=None, axis=None, symbols=None, iview=Ellipsis)[source]

Apply this stencil the input array a. Boundaries are considered periodic.

coo_stencil()[source]

Return a 2d stencil as a sparse coordinate matrix.

Returns:

coo_stencil – Sparse Coordinate Matrix of the stencil.

Return type:

scipy.sparse.coo_matrix

Raises:

RuntimeError – Raised if stencil is not 2d.

has_factor()[source]
hash(keep_only=16)[source]

Hash the stencil with its origin, order and coefficients. The hash algorithm used is sha1. By default only the 16 first chars are kept from the generated hash.

Parameters:

keep_only (int) – Number of chars kept from the hashed hexedecimal string.

Returns:

hash – Hexadecimal hash string of size keep_only.

Return type:

string

is_centered(axe=None)[source]

Check if the stencil is centered (ie. stencil generate a centered finite differences scheme).

Returns:

is_centered

Return type:

bool

is_cross()[source]

Check if the stencil is a cross (zeros everywhere except on a n-dimensional axis aligned cross).

Examples: oo+oo o+oo oo+oo ++++ +++++ o+oo oo+oo o+oo

Returns:

is_cross

Return type:

bool

is_symbolic()[source]

Check if either the stencil leading factor or the stencil coefficients contains symbolic values.

Returns:

is_symbolic

Return type:

bool

items(include_factor=True)[source]

Return an (offset,coefficient) iterator iterating on all non zero coefficients. Offset is taken from origin.

Returns:

it – Zipped offset and coefficient iterator.

Return type:

itertools.iterator

non_zero_coefficients()[source]
refactor(factor)[source]

Factorize the stencil by a new numeric or symbolic value.

Parameters:

factor (dtype or sympy.Expr) – New factor to be applied.

Returns:

self

Return type:

Stencil

replace_symbols(dic)[source]
reshape(new_shape)[source]

Reshape a stencil by adding zeros.

variables()[source]

Symbolic variables used by the stencil.

Returns:

vars

Return type:

set of sympy.Expr